-- stuff we use
local _assert, tonumber, tostring, type, ipairs, pairs, string = _assert, tonumber, tostring, type, ipairs, pairs, string

local oo = require("loop.base")

local debug = require("jive.utils.debug")
local log = require("jive.utils.log").logger("jrmc")

-- our class
module(..., oo.class)



-- init
-- creates an empty database object
function __init(self, theApplet)
	log:error(theApplet, "JRMCOutputHandler:__init()")
	self.applet = theApplet;
	return oo.rawnew(self, {})
end

function play(self, menuItem)
	if (not menuItem.isFolder) then
		self.applet:jrmcRequest("?command=play-item&file=" .. menuItem.file, nil, nil)
	else
		self.applet:jrmcRequest("?command=play-item&location=" .. menuItem.location, nil, nil)
	end
	return true
end

function addEnd(self, menuItem)
	if (not menuItem.isFolder) then
		self.applet:jrmcRequest("?command=add-end&file=" .. menuItem.file, nil, nil)
	else
		self.applet:jrmcRequest("?command=add-end&location=" .. menuItem.location, nil, nil)
	end
	return true
end

function setNowPlayingIndex(self, index)
	self.applet:jrmcRequest("?command=set-now-playing-index&index=" .. index, nil, nil)
	return true
end

function pause(self)
	self.applet:jrmcRequest("?command=play-pause", nil, nil)
	return true
end

function stop(self)
	self.applet:jrmcRequest("view?location=Controls&action=stop", nil, nil)
	return true
end

function next(self)
	--this might want to do a "skip ahead" for video instead of next track....
	self.applet:jrmcRequest("?command=forward", nil, nil)
	return true
end

function previous(self)
	self.applet:jrmcRequest("?command=rewind", nil, nil)
	return true
end

function volumeUp(self)
	self.applet:jrmcRequest("?command=volume-up", nil, nil)
	return true
end

function volumeDown(self)
	self.applet:jrmcRequest("?command=volume-down", nil, nil)
	return true
end

function handleHomeKey(self)
	return true
end

function toggleRepeat(self)
	self.applet:jrmcRequest("view?location=Controls&action=continous", nil, nil)
	return true
end

function toggleShuffle(self)
	self.applet:jrmcRequest("view?location=Controls&action=shuffle", nil, nil)
	return true
end




function __tostring(self)
	return "JRMCOutputHandler"
end

